﻿package mortal.game.view.lotteryDraw
{
    import Message.Public.*;
    import __AS3__.vec.*;
    import com.mui.containers.*;
    import com.mui.containers.globalVariable.*;
    import com.mui.utils.*;
    import fl.data.*;
    import flash.utils.*;

    public class lotteryDrawRecordBox extends GBox
    {
        private var _recordVector:Vector.<lotteryDrawRecodeCellRender>;
        private var _maxItem:int;
        private var _dataProvider:DataProvider;

        public function lotteryDrawRecordBox(param1:int = 10)
        {
            this._maxItem = param1;
            this._recordVector = new Vector.<lotteryDrawRecodeCellRender>;
            super.direction = GBoxDirection.VERTICAL;
            super.verticalGap = 6;
            return;
        }// end function

        public function equal(param1:Object, param2:Object) : Boolean
        {
            if (param1["recordType"] != param1["recordType"])
            {
                return false;
            }
            var _loc_3:* = param1["recordInfo"] as SLotteryRecord;
            var _loc_4:* = param2["recordInfo"] as SLotteryRecord;
            if (this.equalEntityID(_loc_3.entityId, _loc_4.entityId) && _loc_3.playerName == _loc_4.playerName && this.equalDictionary(_loc_3.lotteryItems, _loc_4.lotteryItems) && _loc_3.type == _loc_4.type && this.equalDictionary(_loc_3.lotteryGold, _loc_4.lotteryGold) && _loc_3.level == _loc_4.level && this.equalRecordDate(_loc_3.recordDt, _loc_4.recordDt))
            {
                return true;
            }
            return false;
        }// end function

        private function equalEntityID(param1:SEntityId, param2:SEntityId) : Boolean
        {
            if (param1.type == param2.type && param1.typeEx == param2.typeEx && param1.typeEx2 == param2.typeEx2 && param1.id == param2.id)
            {
                return true;
            }
            return false;
        }// end function

        private function equalDictionary(param1:Dictionary, param2:Dictionary) : Boolean
        {
            var _loc_3:Object = null;
            for (_loc_3 in param1)
            {
                
                if (param1[_loc_3] !== param2[_loc_3])
                {
                    return false;
                }
            }
            return true;
        }// end function

        private function equalRecordDate(param1:Date, param2:Date) : Boolean
        {
            if (param1.time == param2.time)
            {
                return true;
            }
            return false;
        }// end function

        public function clearData() : void
        {
            this.reset();
            this._dataProvider = new DataProvider();
            return;
        }// end function

        public function set dataProvider(param1:DataProvider) : void
        {
            var _loc_2:int = 0;
            if (!param1)
            {
                return;
            }
            var _loc_3:* = param1.length;
            if (this._dataProvider && this._dataProvider.length)
            {
                _loc_2 = 0;
                while (_loc_2 < param1.length)
                {
                    
                    if (this.equal(param1.getItemAt(_loc_2), this._dataProvider.getItemAt(0)))
                    {
                        _loc_3 = _loc_2;
                        break;
                    }
                    _loc_2++;
                }
                _loc_2 = _loc_3 - 1;
                while (_loc_2 >= 0)
                {
                    
                    this.addRecordItem(param1.getItemAt(_loc_2), true);
                    _loc_2 = _loc_2 - 1;
                }
            }
            else
            {
                _loc_2 = 0;
                while (_loc_2 < param1.length)
                {
                    
                    this.addRecordItem(param1.getItemAt(_loc_2));
                    _loc_2++;
                }
            }
            this._dataProvider = param1;
            return;
        }// end function

        public function get dataProvider() : DataProvider
        {
            return this._dataProvider;
        }// end function

        public function removeLastItem() : void
        {
            var _loc_1:* = this._recordVector.pop();
            _loc_1.dispose();
            _loc_1 = null;
            return;
        }// end function

        public function addRecordItem(param1:Object, param2:Boolean = false) : void
        {
            var _loc_3:* = UICompomentPool.getUICompoment(lotteryDrawRecodeCellRender);
            _loc_3.createDisposedChildren();
            _loc_3.data = param1;
            if (param2)
            {
                this.addChildAt(_loc_3, 0);
                this._recordVector.splice(0, 0, _loc_3);
            }
            else
            {
                this.addChild(_loc_3);
                this._recordVector.push(_loc_3);
            }
            if (this._recordVector.length > this._maxItem)
            {
                _loc_3 = this._recordVector.pop();
                this.removeChild(_loc_3);
                _loc_3.dispose();
                _loc_3 = null;
            }
            this.validateNow();
            return;
        }// end function

        override public function validateNow() : void
        {
            updateDisplayList();
            super.validateNow();
            return;
        }// end function

        override public function get height() : Number
        {
            var _loc_4:int = 0;
            var _loc_5:lotteryDrawRecodeCellRender = null;
            var _loc_1:Number = 0;
            var _loc_2:int = 0;
            var _loc_3:* = this._recordVector.length;
            while (_loc_2 < _loc_3)
            {
                
                _loc_5 = this._recordVector[_loc_2];
                _loc_1 = _loc_1 + _loc_5.height;
                _loc_2++;
            }
            return _loc_1 + 10 + verticalGap * (this._recordVector.length - 1);
        }// end function

        private function reset() : void
        {
            var _loc_1:* = this.numChildren - 1;
            while (_loc_1 >= 0)
            {
                
                this.removeChildAt(_loc_1);
                this._recordVector[_loc_1].dispose();
                this._recordVector[_loc_1] = null;
                _loc_1 = _loc_1 - 1;
            }
            this._recordVector = new Vector.<lotteryDrawRecodeCellRender>;
            return;
        }// end function

    }
}
